import axios from "../plugin/http";

//创建投票
export function createVote(payload) {
  return axios
    .post("/api/vote", {
      "header": {
        "sysCode": "VOTE_SERVICE",
        "platform": window.navigator.platform,
        "timestamp": new Date().getTime()
      },
      "payload": {
        "topic": payload.topic,
        "type": payload.type,
        "deadline": payload.deadline, //1528206514000
        "options": payload.options // [{"content": "象棋"}, {"content": "国际象棋"}]
      }
    })
}

//获取投票列表（分页）
export function getVoteListByPage(params) {
  return axios
    .get("/api/vote", {
      params: {
        offset: params.offset,
        limit: params.limit
      }
    })
}

//获取投票详情
export function getVoteDetailById(payload) {
  //payload._id 为vote的id
  return axios
    .get(`/api/vote/${payload._id}`)
}

//删除投票
export function deleteVoteById(payload) {
  //payload._id 为vote的id
  return axios
    .delete(`/api/vote/${payload._id}`, {
      "header": {
        "sysCode": "VOTE_SERVICE",
        "platform": window.navigator.platform,
        "timestamp": new Date().getTime()
      },
    })
}
